package com.alan.wifishare.presenter;

import com.alan.libapi.business.dao.CallbackListener;
import com.alan.wifishare.app.GlobalField;
import com.alan.wifishare.view.iview.IVCNTLinkManager;

/**
 * @className: CNTLinkManagerPS
 * @describtion: CNTLinkManagerPS
 * @author: AlanWang
 * @email: 850267876@qq.com
 * @time: 2016/4/26 18:26
 */
public class CNTLinkManagerPS {

    private IVCNTLinkManager ivcntLinkManager;

    public CNTLinkManagerPS(IVCNTLinkManager ivcntLinkManager) {
        this.ivcntLinkManager = ivcntLinkManager;
    }

    /**
     * 执行绑定设备的操作
     */
    public void unbindDevice(){

        ivcntLinkManager.showProgress();
        GlobalField.businessHttp.postUnbindDevice(
                GlobalField.userSession,
                GlobalField.userBoundDevice.getDeviceId(),
                new CallbackListener<Void>() {
            @Override
            public void onSuccess(Void result) {
                GlobalField.handler.post(new Runnable() {
                    @Override
                    public void run() {
                        ivcntLinkManager.hideProgress();
                        GlobalField.userBoundDevice = null;//解绑成功后将userBoundDevice置空
                        ivcntLinkManager.unBoundLinkSuccess();
                    }
                });
            }

            @Override
            public void onFailure(int errorCode, final String msg) {
                GlobalField.handler.post(new Runnable() {
                    @Override
                    public void run() {
                        ivcntLinkManager.hideProgress();
                        ivcntLinkManager.toastMsg(msg);
                    }
                });
            }
        });
    }
}
